# Base image
FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8 AS runtime

# Set the shell to PowerShell
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; Set-ExecutionPolicy Unrestricted -Force;"]

# Disable IIS auto start
RUN ["cmd", "/S", "/C", "sc", "config", "w3svc", "start=demand"]

# Install LogMonitor.exe
RUN md c:\LogMonitor
COPY tools/logmonitor/. c:/LogMonitor

WORKDIR /

# Copy and extract IBM zip file
COPY tools/CLIENT.zip C:/IBM/
RUN Expand-Archive -Path 'C:/IBM/CLIENT.zip' -DestinationPath 'C:/IBM/' -Force

RUN Start-Process -FilePath 'C:\IBM\CLIENT\setup.exe' -ArgumentList '/u', 'C:\IBM\CLIENT\resp.rsp','/l','C:\IBM\CLIENT\log.txt','/t','C:\IBM\CLIENT\trace.txt' -Wait

RUN c:/windows/system32/inetsrv/appcmd.exe set apppool /apppool.name:DefaultAppPool /processModel.identityType:LocalSystem

# Update IIS config
RUN c:/windows/system32/inetsrv/appcmd.exe set config -section:system.applicationHost/sites /\"[name='Default Web Site'].logFile.logTargetW3C:\"File,ETW\"\" /commit:apphost

# Set the entry point for the container
ENTRYPOINT ["C:\\LogMonitor\\LogMonitor.exe", "C:\\ServiceMonitor.exe", "w3svc"]
